﻿@model IEnumerable<Guan.CMS.Web.ViewModels.Product.ProductListViewModel>
@{
    ViewBag.Title = "产品列表";
    ViewBag.SectionTitleImage = "ico-catalog.png";
}
@using (Html.BeginForm("Remove", "Product"))
{
    <div class="section-header">
        <div class="title">
            @if (ViewBag.SectionTitleImage != null)
            {
                <img src="@Url.Content("~/Content/Images/Admin/" + ViewBag.SectionTitleImage)" alt="" />
            }
            @ViewBag.Title
        </div>
        <div class="options">
            @Html.ActionLink("新增", "Create", "Product", null, new {@class = "k-button"})
            <input type="submit" value="批量删除" class="k-button" onclick="javascript:if(!confirm('确认删除选中？')) return false;"/>
        </div>
    </div>
    <div class="section-body">
        @(Html.Kendo().Grid(Model)
              .Name("product-grid")
              .Columns(columns =>
                           {
                               columns.Template(@<text><input type="checkbox" name="Id" value="@item.Id" class="chkId"/></text>)
                                      .ClientTemplate("<input type=\"checkbox\" name=\"Id\" value=\"#=Id#\" class=\"chkId\" />")
                                      .Title("<input type=\"checkbox\" id=\"chkIdAll\" class=\"chkIdAll\" />").Width(30);
                               columns.Bound(m => m.Name);
                               columns.Bound(m => m.CategoryName);
                               columns.Bound(m => m.IsRecommend)
                                      .ClientTemplate("<img src='" + Url.Content("~/Content/Images/") + "active-#=IsRecommend#" + ".gif' />");
                               columns.Bound(m => m.IsPublished)
                                      .ClientTemplate("<img src='" + Url.Content("~/Content/Images/") + "active-#=IsPublished#" + ".gif' />");
                               columns.Bound(m => m.CreatedTime);
                               columns.Bound(m => m.UpdatedTime);
                               columns.Bound(m => m.MetaKeywords);
                               columns.Bound(m => m.MetaDescription);
                               columns.Bound(m => m.MetaTitle);
                               columns.Bound(m => m.FriendlyName);
                               columns.Template(m => Html.ActionLink("编辑", "Edit", new {id = m.Id}))
                                      .ClientTemplate("<a href=\"Edit/#= Id #\">编辑</a>")
                                      .Title("编辑");
                           }
              ).HtmlAttributes(new {style = "height:460px;"})
              .Groupable().Pageable(p => p.PageSizes(new[] {20, 50, 100})).Sortable().Scrollable().Filterable()
              .DataSource(dataSource => dataSource.Ajax().Read(read => read.Action("ListAjax", "Product")).PageSize(15)))
    </div>
}
@section Scripts
{
    <script>
        $(function () {
            $("#chkIdAll").live("click", function () {
                if ($(this).attr("checked") == "checked") {
                    $("#product-grid").find("input.chkId").attr("checked", "checked");
                } else {
                    $("#product-grid").find("input.chkId").removeAttr("checked", "checked");
                }
            });
        });
    </script>
}
